/**
 * 
 */
package adnotatio.rdf;

/**
 * @author kotelnikov
 */
public class Reference extends PropertyValue {

    /**
     * 
     */
    private static final long serialVersionUID = 149284327849485052L;

    private ID fID;

    /**
     * @param model
     */
    public Reference(Model model, ID id) {
        super(model);
        fID = id;
    }

    /**
     * @see adnotatio.rdf.PropertyValue#accept(adnotatio.rdf.IValueVisitor)
     */
    public void accept(IValueVisitor visitor) {
        Resource resource = getResource(true);
        resource.accept(visitor);
    }

    /**
     * @return the URL
     */
    public ID getID() {
        return fID;
    }

    /**
     * Returns a resource corresponding to this reference.
     * 
     * @param create if this flag is <code>true</code> and there is no
     *        resource with such an URL then a new resource will be created
     * @return a resource corresponding to this reference
     */
    public Resource getResource(boolean create) {
        return fModel.getResource(fID, create);
    }

    /**
     * @see adnotatio.rdf.Entity#getStringValue()
     */
    protected String getStringValue() {
        return fID.getURL();
    }

    /**
     * Returns the value corresponding to this reference
     * 
     * @return the value corresponding to this reference
     * @see adnotatio.rdf.PropertyValue#getValue()
     */
    public Object getValue() {
        return getResource(true);
    }

    /**
     * Sets a new identifier
     * 
     * @param id the new identifer to set
     */
    void setID(ID id) {
        fID = id;
    }

}
